<!--
 * @Author: suo.tianbao suo.tianbao@vpclub.cn
 * @Date: 2023-09-01
 * @LastEditors: suo.tianbao suo.tianbao@vpclub.cn
 * @LastEditTime: 2023-09-01
 * @FilePath: /element-admin/src/views/GitUsers.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div id="Member-Point-History-page">
    <!--顶部搜索栏-->
    <div class="col-md-12">
      <el-row :gutter="20">
        <el-col :span="22" :offset="1" class="clearfix">
          <el-form :inline="true" :model="query" class="demo-form-inline">
            <el-form-item>
              <el-button type="danger" @click="handleMemExut" size="small">1.全会员餐食执行计算</el-button>
            </el-form-item>
            <el-form-item>
              <el-button type="danger" @click="handleDayExut" size="small">2.统计会员餐食总量计算</el-button>
            </el-form-item>
            <el-form-item label="查询日期"  prop="time">
              <el-date-picker
                  v-model="today_value"
                  align="right"
                  type="date"
                  placeholder="选择日期"
                  :picker-options="pickerOptions">
              </el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
    </div>
    <!--中部数据表格栏-->
    <div class="col-md-12">
      <el-row :gutter="20">
        <el-col :span="7" :offset="1" class="clearfix">
          <el-table :data="FoodCalDayList"
                    :cell-style="{padding:'3px'}"
                    :row-style="{height:'30px'}"
                    :height="tableHeight" :key="isIndex" style="width: 100%" v-loading="isLoading" border stripe
                    row-key="id">
            <el-table-column v-if="isIndex == 1" type="index" label="序号" width="75" fixed></el-table-column>
            <el-table-column prop="name" label="食材名称"></el-table-column>
            <el-table-column prop="intake" label="食材总量"></el-table-column>
          </el-table>
        </el-col>
        <el-col :span="15" :offset="0" class="clearfix">
          <el-card :body-style="{ padding: '0px' }">
            <template>
              <div id="mainPie" style="height:650px;"></div>
            </template>
          </el-card>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
<script>
import {mapMutations} from "vuex";
import {drawPie, exutDayDinnerTot, exutMemDinner} from "@/api/MemberWeight";

export default {
  name: "FoodCalDayMapView",
  components: {},
  data() {
    return {
      isIndex: 1,
      isLoading: false,
      query: {
        key: '',
        pageSize: 20,
        pageNum: 1,
      },
      tableHeight: 650,
      FoodCalDayList: [],
      myPieChart: [],
      today_value: new Date(),
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            picker.$emit('pick', new Date());
          }
        }, {
          text: '昨天',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24);
            picker.$emit('pick', date);
          }
        }, {
          text: '一周前',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', date);
          }
        }]
      },
    }
  },
  computed: {},
  methods: {
    ...mapMutations(['add_tab']),
    init_obj() {
      return {
        FoodCalDayList: [],
      }
    },
    handleMemExut() {
      this.isLoading = true;
      exutMemDinner().then(res => {
        if (res.code == 200) {
          this.isLoading = false;
          this.FoodCalDayList = [];
          this.$notify({title: '执行成功', message: '数据操作完成', type: 'success', offset: 100});
        }
      }).catch(err => {
        this.$notify({title: '执行失败', message: '数据操作异常' + err, type: 'error', offset: 100});
      });
    },
    handleDayExut() {
      this.isLoading = true;
      exutDayDinnerTot().then(res => {
        if (res.code == 200) {
          this.isLoading = false;
          this.FoodCalDayList = res['data'];
          let myPieChart = document.getElementById("mainPie");
          let pieChart = drawPie(myPieChart, res['pie']);
          window.addEventListener('resize', () => {
            setTimeout(() => {
              pieChart.resize();
            })
          })
          this.myPieChart.push(pieChart);
          this.$notify({title: '执行成功', message: '数据操作完成', type: 'success', offset: 100});
        }
      }).catch(err => {
        this.$notify({title: '执行失败', message: '数据操作异常' + err, type: 'error', offset: 100});
      });
    },


  },
  created() {

  },
  mounted() {
  },
}
</script>
<style scoped>

.demo-date-picker {
  display: flex;
  width: 100%;
  padding: 0;
  flex-wrap: wrap;
}

.demo-date-picker .block {
  padding: 30px 0;
  text-align: center;
  border-right: solid 1px var(--el-border-color);
  flex: 1;
}

.demo-date-picker .block:last-child {
  border-right: none;
}

.demo-date-picker .demonstration {
  display: block;
  color: var(--el-text-color-secondary);
  font-size: 14px;
  margin-bottom: 20px;
}

</style>